<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="./css/bootstrap-v4.6.0.css" />
    <link rel="stylesheet" href="./css/login.css" />
  </head>

  <body>
    <div class="login-box">
      <div class="form-group">
        <label for="username">Account</label>
        <!-- 账号 -->
        <input
          type="text"
          class="form-control"
          id="username"
          autocomplete="off"
        />
        <small id="emailHelp" class="form-text text-muted"
          >The available account is <strong>admin</strong></small
        >
      </div>
      <div class="form-group">
        <!-- 密码 -->
        <label for="password">Password</label>
        <input type="password" class="form-control" id="password" />
        <small id="emailHelp" class="form-text text-muted"
          >The available password is <strong>123456</strong></small
        >
      </div>
      <button type="submit" class="btn btn-primary" id="btnLogin">
        Submit
      </button>
    </div>

    <script src="./lib/axios.js"></script>

    <script>
     const usernameInput=document.querySelector('#username')
     const passwordInput=document.querySelector('#password')
     const btn=document.querySelector('#btnLogin')

    //  btn.addEventListener('click',function(){
    //   const username=usernameInput.value
    //   const password=passwordInput.value
    //   axios.post('http://ajax-api.itheima.net/api/login',{username,password}).then(({data:res})=>{
    //     alert(`${res.message} ${res.data.account}欢迎光临红浪漫`)
    //   })
    //   .catch(error=>{
    //     console.clear()
    //     alert('傻逼,正确输入用户名密码')
    //   })
    //  })

    btn.addEventListener('click',async function(){
      const username=usernameInput.value
      const password=passwordInput.value

    try {
      const {data:res}=await axios.post('http://ajax-api.itheima.net/api/login',{username,password})
      alert(`${res.message}  欢迎您${res.data.account}女士`)
    } catch (error) {
      alert('傻逼,正确输入用户名密码')
    }
    })
    </script> 
  </body>
</html>
